package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.CategoryDto;
import com.ymatou.iapi.productmanager.parameter.GetCategorysBean;
import com.ymatou.iapi.productmanager.service.GetCategorysCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
import org.apache.http.client.ClientProtocolException;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
*获取买手所有的商品品类
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetCategorys{
	private static GetCategorysBean getcategorysBean;
	private static GetCategorysCall getcategorysCall;
	private static Integer userId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买手所有的商品品类");
	}

	@Before
	public void caseUp() {
		getcategorysBean=new GetCategorysBean();
		getcategorysCall=new GetCategorysCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getcategorysCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCategorys_001() {
		Logger.start(true,"获取买手所有的商品品类");
		try {
			getcategorysBean.setUserId(userId);
			getcategorysCall.setData(getcategorysBean);
			checkCatagorys(userId,getcategorysBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCategorys_002() {
		Logger.start(true,"获取买手所有的商品品类,不传买手id");
		try {
			getcategorysCall.setData(getcategorysBean);
			getcategorysCall.callService();
			Logger.verifyEquals("400", getcategorysCall.getString("Code"), "买手id不能为哦空");
			//checkCatagorys(userId,getcategorysBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public void checkCatagorys(Integer userId,GetCategorysBean getcategorysBean) throws InterruptedException, ClientProtocolException, IOException{
		getcategorysCall.callService();
		Logger.verifyEquals("200", getcategorysCall.getString("Code"), "验证Code");
		List<CategoryDto> sCategorys = getcategorysCall.getCategorys();
		List<Map> categorys = new YmtProductsIWapper().getCategorys(userId);
		Logger.debug(categorys);
		for(int i = 0;i < sCategorys.size();i++){
			if((Integer)categorys.get(i).get("categoryId")==sCategorys.get(i).getCatagoryId()){
				Logger.verifyEquals(sCategorys.get(i).getCategoryNameEn(), categorys.get(i).get("categoryNameEn").toString(), "验证categoryNameEn");
				Logger.verifyEquals(sCategorys.get(i).getCategoryName(), categorys.get(i).get("categoryName").toString(), "验证categoryName");
			}
		}
	}
}